<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>03_DOM操作-替换元素</title>
</head>
<body>

  <ul id="list" class="panel">
    <li class="li-1">li-1</li>
    <li class="li-2">li-2</li>
    <li class="li-3">li-3</li>
    <li class="li-4">li-4</li>
    <li class="li-5">li-5</li>
  </ul>

  <li class="li-6">li-6</li>
  <script src="../libs/jquery-3.6.0.js"></script>

  <script>
    $(function() {
      let $ul = $('#list')
      let $span = $('<span>替换元素111</span>')
      // 1. 将li替换为 span元素 .replaceAll(target)
      // $ul.children().replaceAll($span)
      // $('<span>')
      //     .addClass('content')
      //     .text('span替换元素')
      //     .css('color', 'red')
      //     // .replaceAll($ul.children())
      //     .replaceAll( 'ul li' )

      // 2. 将span替换为li元素 .replaceWith(target)
      $ul.children().replaceWith($span)
    })


  </script>
  
</body>
</html>